package com.woniuxy.credit_loans.collection_zhang.service.Impl;

import com.woniuxy.credit_loans.collection_zhang.service.CollectionService;
import com.woniuxy.credit_loans.entity.Collection;
import com.woniuxy.credit_loans.mapper.CollectionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class CollectionServiceImpl implements CollectionService {

    @Autowired
    private CollectionMapper collectionMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        collectionMapper.deleteByPrimaryKey(id);
        return 0;
    }

    @Override
    public List<Collection> selectAll(String input) {
        List<Collection> collections = collectionMapper.selectAll(input);
        return collections;
    }

    @Override
    public int insertSelective(Collection record) {
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
         String format = simpleDateFormat.format(new Date());
         record.setCollectionBy1(format);
         collectionMapper.insertSelective(record);
         return 0;
    }

    @Override
    public Collection selectByPrimaryKey(Long id) {
         Collection collection = collectionMapper.selectByPrimaryKey(id);
        return collection;
    }

    @Override
    public int updateByPrimaryKeySelective(Collection record) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(new Date());
        record.setCollectionBy2(format);
        collectionMapper.updateByPrimaryKeySelective(record);
        return 0;
    }
}
